package br.com.imob.modelo;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author Gilton Nascimento
 */
@Entity
@Table(name = "\"ENDERECO\"", catalog = "imob", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Endereco.findAll", query = "SELECT e FROM Endereco e"),
    @NamedQuery(name = "Endereco.findByEnderecoId", query = "SELECT e FROM Endereco e WHERE e.enderecoId = :enderecoId"),
    @NamedQuery(name = "Endereco.findByEndereco", query = "SELECT e FROM Endereco e WHERE e.endereco = :endereco"),
    @NamedQuery(name = "Endereco.findByNumero", query = "SELECT e FROM Endereco e WHERE e.numero = :numero"),
    @NamedQuery(name = "Endereco.findByLoteamento", query = "SELECT e FROM Endereco e WHERE e.loteamento = :loteamento"),
    @NamedQuery(name = "Endereco.findByComplemento", query = "SELECT e FROM Endereco e WHERE e.complemento = :complemento"),
    @NamedQuery(name = "Endereco.findByReferencia", query = "SELECT e FROM Endereco e WHERE e.referencia = :referencia")})
public class Endereco implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
//  <editor-fold defaultstate="collapsed" desc="Geradores de Sequencias">
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_STORE")
    @SequenceGenerator(name = "SEQ_STORE", sequenceName = "next_endereco")// </editor-fold>
    @Basic(optional = false)
    @Column(name = "endereco_id", nullable = false)
    private Integer enderecoId;
    
    @Basic(optional = false)
    @Column(name = "endereco", nullable = false, length = 130)
    private String endereco;
    
    @Column(name = "numero")
    private Integer numero;
    
    @Column(name = "loteamento", length = 80)
    private String loteamento;
    
    @Column(name = "complemento", length = 200)
    private String complemento;
    
    @Column(name = "referencia", length = 2147483647)
    private String referencia;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "endereco", fetch = FetchType.LAZY)
    private List<Empresa> empresaList;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "endereco", fetch = FetchType.LAZY)
    private List<Pessoa> pessoaList;
    
    @OneToMany(mappedBy = "endereco", fetch = FetchType.LAZY)
    private List<Corretor> corretorList;
    
    @JoinColumn(name = "bairro_id", referencedColumnName = "bairro_id", nullable = false)
    @ManyToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Bairro bairro;
    
    @OneToMany(mappedBy = "endereco", fetch = FetchType.LAZY)
    private List<Construtora> construtoraList;

    public Endereco() { }

    public Endereco(Integer id) { enderecoId = id; }
    public Endereco(String ender) { endereco = ender; }

    public Endereco(Integer id, String ender) {
        enderecoId = id;
        endereco = ender;
    }
    
    public Endereco(Integer id, String tipoStr, String arg) {
    	enderecoId = id;
    	if( "endereco".equals(tipoStr) )
    		endereco = arg;
    	if( "loteamento".equals(tipoStr) )
    		loteamento = arg;
    	if( "complemento".equals(tipoStr) )
    		complemento = arg;
    	if( "referencia".equals(tipoStr) )
    		referencia = arg;
    }
    
    public Endereco(Integer id, String tipoStr, String arg, int num) {
    	this(id, tipoStr, arg);
    	numero = num;
    }
    
    public Endereco(Integer id, int number) {
    	enderecoId = id;
    	numero = number;
    	
    }
    public Endereco(int id, String ender, int num, String loteament, String compl, String ref) {
    	enderecoId = id;
    	endereco = ender;
    	numero = num;
    	loteamento = loteament;
    	complemento = compl;
    	referencia = ref;
    }

    
//    Getts and Setts
    public Integer getEnderecoId() {
        return enderecoId;
    }

    public void setEnderecoId(Integer enderecoId) {
        this.enderecoId = enderecoId;
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    public Integer getNumero() {
        return numero;
    }

    public void setNumero(Integer numero) {
        this.numero = numero;
    }

    public String getLoteamento() {
        return loteamento;
    }

    public void setLoteamento(String loteamento) {
        this.loteamento = loteamento;
    }

    public String getComplemento() {
        return complemento;
    }

    public void setComplemento(String complemento) {
        this.complemento = complemento;
    }

    public String getReferencia() {
        return referencia;
    }

    public void setReferencia(String referencia) {
        this.referencia = referencia;
    }

    public List<Empresa> getEmpresaList() {
        return empresaList;
    }

    public void setEmpresaList(List<Empresa> empresaList) {
        this.empresaList = empresaList;
    }

    public List<Pessoa> getPessoaList() {
        return pessoaList;
    }

    public void setPessoaList(List<Pessoa> pessoaList) {
        this.pessoaList = pessoaList;
    }

    public List<Corretor> getCorretorList() {
        return corretorList;
    }

    public void setCorretorList(List<Corretor> corretorList) {
        this.corretorList = corretorList;
    }

    public Bairro getBairro() {
        return bairro;
    }

    public void setBairro(Bairro bairro) {
        this.bairro = bairro;
    }

    public List<Construtora> getConstrutoraList() {
        return construtoraList;
    }

    public void setConstrutoraList(List<Construtora> construtoraList) {
        this.construtoraList = construtoraList;
    }

    public Object[] getValues() {
    	Object[] objects = {enderecoId, endereco, numero, complemento, loteamento, referencia};
    	return objects; 
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (enderecoId != null ? enderecoId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Endereco)) {
            return false;
        }
        Endereco other = (Endereco) object;
        if ((this.enderecoId == null && other.enderecoId != null) || (this.enderecoId != null && !this.enderecoId.equals(other.enderecoId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.com.imob.modelo.Endereco[enderecoId=" + enderecoId + "]";
    }

}